home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Best way to store in program messages?
- Date: 21 Feb 1996 10:50:30 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4gfphmINNdjt@keats.ugrad.cs.ubc.ca>
- References: <4gckb4$77e@news.mistral.co.uk>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4gckb4$77e@news.mistral.co.uk>,
- Mike Barnard <mikebarnard@mistral.co.uk> wrote:
- >Hi all.
- >
- >Thanks for your past help.
- >
- >My last question threw up another in my mind. How do you, the pro's
- >out there, store your in-program messages?
- >
- >So far I havn't written amything of any size at all. I've gotten away
- >with having a function to display a title in a box and used...
- >
- >char title1[]="The program title";
- >char title2[]="A copyright message";
- >
- >...at the start of that function then cprintf'd the line I wanted.
- >Same with the menu I'm working on now, but putting the menuitem
- >description in a structure.
- >
- >But supposing I did a text adventure? Hundreds of messages to store.
- >Or a long list of error messages and other inprogram messages giving
- >instructions to the user. I'd obviously like them to be stored out of
- >harms way, not taking up too much memory, but easily accessable. Would
- >you store them in a seperate file #included into the main file? A
- >seperate function holding them? It would be nice to have them all in
- >one place for ease of editing.
-
- I probably would not store a text adventure's database as static declarations.
- The worst thing I have done along these lines was statically declaring a tree
- structure for a hierarchical help system. Doing it statically enabled me to
- knock it off quickly. Basically, each node in the tree was a structure
- containing a variable array of strings, as well as a pointers to child nodes
- next node on the same level, previous and the parent node. You can statically
- build a tree of arbitrary depth this way. You could build an adventure map this
- way if you were so inclined.
-
- It would be better to define your own language which describes the text in a
- structured way, and then have your program parse this language and build
- dynamic data structures.
-
- The UNIX-based LPMud software allows players to dynamically extend the Mud
- world at run-time by writing code in an interpreted language called LPC, which
- superficially resembles C. A module of the world is coded into an LPC file
- which determines the behavior of that little section of the Mud.
-
- This is a lot more interesting than static text, since the world is constantly
- evolving even as you play the game.
-
- >Also I'm not sure what memory is used by char arrays as opposed to
- >mallocing (something I havn't touched - yet). I've heard of the heap,
- >near and far memory, data and code segments... huh? As an extra
- >question can you point me to a good FAQ/Tutorial on heaps, near and
- >far etc?
-
- The comp.lang.c FAQ does touch on dynamic memory allocation with malloc() and
- friends, but I wouldn't say that it serves as a tutorial. Things like "near and
- far" are best forgotten until you learn about data structures and program
- design (in a language independent fashion). Get book from the library about
- data structures and program design, perhaps one that uses examples from the C
- language. A copy of "The C Programming Language" by Kernighan and Ritchie is
- also a very useful companion, and will probably serve you as such for years.
-
- I recently snagged a book called ``Fundamental Structures of Computer Science''
- by William A. Wulf, Mary Shaw, Paul N. Hilfinger, and Lawrence Flon.
- (ISBN 0-201-08824-X) for $0.99 at a discard sale held by a university library.
- It's a neat paperback jam-packed with the stuff of undergraduate computer
- science. Much of it is review for me, but it's just so compact, I instantly
- knew that it would make a handy reference. Plus the price was right...
- It teaches about finite state machines, models of control flow, abstract data
- types, algorithm efficiency, etc.
-
- Such books can teach you a lot, if you are willing to invest the time.
- --
-
-